/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.common.parsers.html;

import java.io.Reader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;


/**
 * An HTML parser that extracts all references.
 *
 * @see HTMLPlainTextExtractor
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/03/26 11:47:32 $
 */
class RefsParser extends HTMLParser {
    protected List refList;

    /**
     * Constructs the RefsParser.
     *
     * @param reader             the <code>Reader</code> that will supply an HTML to parse
     */
    public RefsParser(Reader reader) {
        super(reader, null, false, null);
        refList = new ArrayList();
    }

    protected void addText(String text) throws IOException {}

    protected void addSpace() throws IOException {}

    /**
     * Considers text -- adds it to the ref list.
     *
     * @param text the text ro be added to the list
     *
     * @throws java.io.IOException
     */
    protected void considerText(String text) throws IOException {
        refList.add(text);
    }

    /**
     * Considers space -- actually does nothing.
     *
     * @throws java.io.IOException
     */
    protected void considerSpace() throws IOException {}

    protected void processTag(String tagName, HashMap attributes,
                              boolean closing) throws IOException {
        checkoutAttribute(attributes, "src");
        checkoutAttribute(attributes, "href");
        checkoutAttribute(attributes, "background");
    }

    public List getExtractedRefs() {
        return refList;
    }
}
